﻿@using System.Collections.Generic
@using Microsoft.AspNetCore.Http
@using Microsoft.AspNetCore.Http.Authentication
@using Microsoft.AspNetCore.Mvc.Localization
@model LoginViewModel
@inject SignInManager<ApplicationUser> SignInManager
@inject IViewLocalizer Localizer

@{
    ViewData["Title"] = Localizer["Log in"];
}

<h2>@ViewData["Title"].</h2>
<div class="row">
    <div class="col-md-8">
        <section>
            <form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
                <h4>@Localizer["Use a local account to log in."]</h4>
                <hr>
                <div asp-validation-summary="All" class="text-danger"></div>
                <div class="form-group">
                    <label asp-for="Email" class="col-md-2 control-label"></label>
                    <div class="col-md-10">
                        <input asp-for="Email" class="form-control">
                        <span asp-validation-for="Email" class="text-danger"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label asp-for="Password" class="col-md-2 control-label"></label>
                    <div class="col-md-10">
                        <input asp-for="Password" class="form-control">
                        <span asp-validation-for="Password" class="text-danger"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <div class="checkbox">
                            <input asp-for="RememberMe">
                            <label asp-for="RememberMe"></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <button type="submit" class="btn btn-default">@Localizer["Log in"]</button>
                    </div>
                </div>
                <p>
                    <a asp-action="Register">@Localizer["Register as a new user?"]</a>
                </p>
                <p>
                    <a asp-action="ForgotPassword">@Localizer["Forgot your password?"]</a>
                </p>
            </form>
        </section>
    </div>
    <div class="col-md-4">
        <section>
            <h4>@Localizer["Use another service to log in."]</h4>
            <hr>
            @{
                var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList();
                if (loginProviders.Count == 0)
                {
                    <div>
                        <p>
                            @Localizer["There are no external authentication services configured. See <a href=\"http://go.microsoft.com/fwlink/?LinkID=532715\">this article</a> " +
                                       "for details on setting up this ASP.NET application to support logging in via external services."]
                        </p>
                    </div>
                }
                else
                {
                    <form asp-controller="Account" asp-action="ExternalLogin" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
                        <div>
                            <p>
                                @foreach (var provider in loginProviders)
                                {
                                    <button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
                                }
                            </p>
                        </div>
                    </form>
                }
            }
        </section>
    </div>
</div>

@section Scripts {
    @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}
